<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>多物体运动</title>


    <style>
        div {
            width: 100px;
            height: 50px;
            background-color: red;
            margin-top: 10px;
        }
    </style>

</head>

<body>
    <div>
        <!-- <div style="width: 10px;background-color: black;"></div> -->
    </div>
    <div></div>
    <div></div>
    <div></div>

</body>
<script>
    var div = document.getElementsByTagName('div');
    var time;



    for (var i = 0; i < div.length; i++) {

        div[i].onmouseover = function() {
            Strat(this, 300);
        }
        div[i].onmouseout = function() {
            Strat(this, 100);
        }
    }

    function Strat(obj, target) {
        clearInterval(obj.time);
        obj.time = setInterval(function() {
            var speed = (target - obj.offsetWidth) / 8;
            speed = speed > 0 ? Math.ceil(speed) : Math.floor(speed);
            if (obj.offsetWidth == target) {
                clearInterval(obj.time);
            } else {
                obj.style.width = (obj.offsetWidth + speed) + 'px';
            }
        }, 18);
    }
</script>

</html>